{% extends "base.html" %}


{% block  title %}脚本执行{% endblock %}

{% block page-content %}


    <div class="row wrapper border-bottom white-bg page-heading">
        <div class="col-lg-10">
            <h2>脚本执行</h2>
            <ol class="breadcrumb">
                <li>
                    <a href="/index.html">主页</a>
                </li>
                <li>
                    <a>任务</a>
                </li>
                <li class="active">
                    <strong>脚本执行</strong>
                </li>
            </ol>
        </div>
        <div class="col-lg-2">

        </div>
    </div>
<div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-lg-5">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>脚本执行</h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                            <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                                <i class="fa fa-wrench"></i>
                            </a>
                            <ul class="dropdown-menu dropdown-user">
                                <li><a href="#">选项 1</a>
                                </li>
                                <li><a href="#">选项 2</a>
                                </li>
                            </ul>
                            <a class="close-link">
                                <i class="fa fa-times"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <div class="table-responsive">
                            <form class="form-horizontal  cmd_from">
                                <table class="table table-striped table-bordered table-hover dataTables-example">
                                    <thead>
                                    <tr>
                                        <th width="20"><input type="checkbox" id="CheckedAll"></th>
                                        <th>外网IP</th>
                                        <th>管理IP</th>
                                        <th>产品线</th>

                                    </tr>
                                    </thead>
                                    <tbody>

                                    {% for   row   in   asset_list %}

                                        <tr class="gradeA" id="{{ row.id }}">
                                            <td><input type="checkbox" value="{{ row.id }}" name="id"></td>
                                            <td class="center"><a
                                                    href="{% url  "asset:asset_detail"   row.id %}">{{ row.network_ip }}</a>
                                            </td>
                                            <td class="center">{{ row.manage_ip }}</td>
                                            <td class="center">{{ row.product_line }}
                                                </td>
                                        </tr>
                                    {% endfor %}

                                    </tbody>

                                </table>
                                <div class="ibox-content">
                             {%  for row in sh%}
                                   <div class="form-group"><label class="col-sm-2 control-label">工具</label>
                <input type="text"   name="shid" style="display:none" value="{{ row.id }}"/>
                                <div class="col-lg-4 col-sm-6"><input type="text" class="form-control" name="name"  required=""  value="{{ row.name }}">
                                </div>
                            </div>
                                    {% endfor %}
                            <div class="hr-line-dashed"></div>



                                    <div class="form-group">
                                        <div class="col-sm-6 col-sm-offset-2">

                                            <a id="cmd" class="btn btn-primary" type="submit">提交</a>
                                            <button class="btn btn-white" type="button" onclick='clearBody()'>取消
                                            </button>
                                        </div>
                                    </div>

                                </div>

                            </form>
                        </div>

                    </div>
                </div>
            </div>
            <div class="col-sm-7">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>输出结果
                        </h5>
                        <div class="ibox-tools">
                            <a class="collapse-links">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                            <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                                <i class="fa fa-wrench"></i>
                            </a>
                            <ul class="dropdown-menu dropdown-user">
                                <li><a href="#">配置选项 1</a>
                                </li>
                                <li><a href="#">配置选项 2</a>
                                </li>
                            </ul>
                            <a class="close-link">
                                <i class="fa fa-times"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content  pres"   >

                          <pre> <span id="err"></span></pre>

                    </div>
                </div>
            </div>
        </div>
    </div>



{% block footer-js %}

<script>


    $(function () {


        $('#cmd').click(function () {
            $.ajax({
                url: "/tasks/tools-script.html",
                type: 'POST',
                data: $('.cmd_from').serialize(),
                success: function (data) {
                    var obj = JSON.parse(data);
                    cons = "";
                    if (obj.data) {

                         $.each(obj, function (data, values) {
                            $.each(values, function (index, value) {
                                cons += "<pre>"+"主机:" + value.ip + "\n" + "结果: \n " + value.data + "</pre>"

                            });
                            $(".pres").html(cons); //把内容入到这个div中即完成
                        });

                    } else {
                        $('#err').text(obj.error);
                    }

                }

            })
        });





    });

    function clearBody() {
        location.reload()
    }

</script>


{% endblock %}

{% endblock %}